package com.tzl.design_pattern.prototype_pattern;

import java.io.*;
import java.util.List;

/**
 * @author Zhilei Tang
 * @date Created in 2020/11/15 14:01
 */
public class Prototype_B implements Cloneable, Serializable {

  private String name;
  private int age;
  private List<String> phoneList;

  public Object clone() throws CloneNotSupportedException {
    try {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(bos);
      oos.writeObject(this);

      ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bis);

      Prototype_B clone = (Prototype_B) ois.readObject();
      return clone;
    } catch (Exception e) {
      return null;
    }
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int getAge() {
    return age;
  }

  public void setAge(int age) {
    this.age = age;
  }

  public List<String> getPhoneList() {
    return phoneList;
  }

  public void setPhoneList(List<String> phoneList) {
    this.phoneList = phoneList;
  }
}
